using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace GameUI {
	public class WeaponIconController:MonoBehaviour {

		private void Start() {
			images=GetComponentsInChildren<Image>();
		}

		void Update() {
			boundWeapon=Player.instance.GetWeapon(weaponSlot);
			bool doDisplay = true;
			if(Player.instance.weaponSlotCount<=weaponSlot) doDisplay=false;
			if(InventoryUIController.instance.isActiveAndEnabled) doDisplay=false;

			bool displayCooldown = true;

			if(doDisplay) {
				weaponImage.color=Color.white;
				baseImage.color=Color.white;

				weaponImage.sprite=Player.instance.GetWeapon(weaponSlot).weapon.stat.sprite;
				float displayAmount = boundWeapon.weapon.displayAmount;
				if(displayAmount>=1) displayCooldown=false;
				cooldownImage.fillAmount=displayAmount;

			} else {
				weaponImage.color=Color.clear;
				baseImage.color=Color.clear;
				displayCooldown=false;
			}

			frame.SetActive(Player.instance.weaponIndex==weaponSlot&&doDisplay);
			cooldownBase.SetActive(displayCooldown);

		}

		WeaponSlot boundWeapon;

		[SerializeField] int weaponSlot;
		[SerializeField] GameObject frame;
		[SerializeField] Image baseImage;
		[SerializeField] Image weaponImage;
		[SerializeField] Image cooldownImage;
		[SerializeField] GameObject cooldownBase;
		Image[] images;

	}
}